<?php
/** .-------------------------------------------------------------------
* |    Author: 熊伟洋 <chelious@foxmail.com>
* |    WeChat: hello_McGrady
* |    	   QQ: 434493420
* |     Motto: Hungry & Humble
* |---------------------------------------------------------------------
* |    Copyright (c) 2012-2020, www.chelious.com. All Rights Reserved.
* '-------------------------------------------------------------------*/

namespace app\home\controller;

/**
 * Class Common
 * @package app\home\controller
 * 公共控制器
 */
class Common{

    public function __construct()
    {
        //处理头部的导航栏数据
        //初始化模型
        $comHead = Db::table('category')
                    ->where('pid',0)
//                    ->limit(4)
//                    ->field(['cid','cname'])
                    ->get();
//        p($comHead);
        View::with('comHead',$comHead);


        //处理分类列表
        $comCate = Db::table('category')
                    ->field(['cid','cname'])
                    ->get();
        //()中的数据，该分类下有多少文章
        foreach ($comCate as $k => $v){
            $comCate[$k]['total'] = Db::table('article')
                                    ->where('category_cid',$v['cid'])
                                    ->where('is_recycle',0)
                                    ->count();
        }
//        p($comCate);

        View::with('comCate',$comCate);

        //获取标签表的数据
        $comTag = Db::table('tag')->get();
        View::with('comTag',$comTag);

        //获取网站配置的数据
        $comWebSet = Db::table('webset')->lists('value');
//        p($comWebSet);
        View::with('comWebSet',$comWebSet);

        //友情链接的数据
        $linkData = Db::table('link')->field(['lname','url'])->get();
//        p($linkData);
        View::with('linkData',$linkData);

        //最新文章的数据
        $articleData = Db::table('article')
            ->orderBy('sendtime','desc')
            ->limit(3)
            ->field(['aid','title','sendtime'])
            ->get();
//        p($articleData);
        View::with('articleData',$articleData);

        //推荐文章
        $goodArticle = Db::table('article')
            ->orderBy('sendtime','desc')
            ->limit(6)
            ->field(['aid','title','sendtime'])
            ->get();
        View::with('goodArticle',$goodArticle);

        //热门点击
        $hotData = Db::table('article')
            ->join('category','category_cid','=','cid')
            ->orderBy('click','desc')
            ->limit(8)
            ->field(['aid','title','cid','cname'])
            ->get();
        View::with('hotData',$hotData);

    }

}
